package utils
{
	/**
	 *@date 2015-12-27 下午3:38:05
	 *@author zhouhonghui
	 */
	public class ExHtmlReg
	{
		public function ExHtmlReg()
		{
			
		}
		public function test():void
		{
			var reg1:RegExp = new RegExp("\n$","g");
			var str:String = "哈哈哈\n真的吗\n你\n是\n否还好滴哈\n";
			var s:String = str.replace(reg1,"<br>");
			trace(s);
			
		}
		public function testHtml():void
		{
			var html:String = "<font color='#fff000' size='14' >我的logo是很漂亮。<font>你好吗</font></font>";
			//用于匹配<(/)(ident) (attr='value')>字符串的正则表达式
			var reg:RegExp = new RegExp("<([/]{0,1})([a-zA-Z][a-zA-Z0-9]*)([^>]*)>", "s");
			reg = new RegExp("<([/]{0,1})([a-zA-Z]*)([^>]*)>","s"); //支持嵌套
			var obj:Object = reg.exec(html);
			while(obj)
			{
				if(obj.index>0)
				{
					var text:String = html.substr(0, obj.index);
					trace(text);
				}
				html = html.substring(obj.index + obj[0].length);				
				obj = reg.exec(html);
				trace(obj);
			}
			trace(obj);
			
			var attr:String = "color='#fff000' size=" +
				"'14'";
			//用于匹配html中的属性,标志中不能使用x因为表达式中的空格有意义
			var reg2:RegExp = new RegExp("([a-zA-Z_][a-zA-Z_0-9]*)[ \t]*=[ |\t]*'([^']*)'|([a-zA-Z_][a-zA-Z_0-9]*)[ \t]*=[ |\t]*\"([^\"]*)\"", "sg");
			
			reg2 = new RegExp("([a-zA-Z]*)[ \t]*=[ \t']*([^']*)");
			
			obj = reg2.exec(attr);
			while(obj)
			{
				var i:int = obj.index + obj[0].length;
				attr = attr.substring(i);
				obj = reg2.exec(attr);
				trace(obj);
			}
			//attr=" size='14'";
			var reg3:RegExp = reg2; //new RegExp("([a-zA-Z_][a-zA-Z_0-9]*)[ \t]*=[ |\t]*'([^']*)'|([a-zA-Z_][a-zA-Z_0-9]*)[ \t]*=[ |\t]*\"([^\"]*)\" ");
			obj = reg2.exec(attr);
			trace(obj);
		}
		
	}
}